package com.maas.util.mybatis.jpa.littlenb.conditions.service.impl;


import com.maas.util.mybatis.jpa.littlenb.conditions.lambda.Property;
import com.maas.util.mybatis.jpa.littlenb.conditions.service.MapperService;
import com.maas.util.mybatis.jpa.littlenb.conditions.utils.LambdaUtils;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import java.lang.reflect.Field;
import java.util.*;



/**
 * @author YangYu
 * 通用实现
 */
public class MapperServiceImpl<T> extends BaseMapperService<T> implements MapperService<T> {
    Map<String, Object> eqMap = null;

    T entity;
    T setEntity;
    MapperServiceImpl.MethodEnum methodEnum;

    public enum MethodEnum {
        /**
         * 调用函数
         */
        INSERT, BATCH_INSERT, LIST, COUNT, UPDATE, DELETE
    }

    @Override
    public MapperService<T> eq(Property property, Object value) {
        return eq(LambdaUtils.fieldName(property), value);
    }

    @Override
    public MapperService<T> eq(String key, Object value) {
        (eqMap = map(eqMap)).put(key, value);
        return this;
    }

    Map<String, Object> map(Map<String, Object> conditionMap) {
        return (conditionMap == null ? new HashMap<>() : conditionMap);
    }

    /**
     * 重置查询条件
     */
    void resetCondition() {
        this.eqMap = null;
        //this.conditionSql = "";
        //this.sqlBuilder = new StringBuilder();
    }


    @Override
    public List<T> list(T entity) {
        this.methodEnum = MethodEnum.LIST;
        this.entity = entity;
        List<T> list = (List<T>) execute();
        if (list ==null || list.size() <= 0) {
            return list;
        }

        // 扩展操作
        super.annoExtend(list);

        return list;
    }


    /**
     * 执行调用
     */
    private Object execute() {
        return null;
    }

}
